//
//  ZZMainNewsTableViewCell.m
//  ZZNews
//
//  Created by 周英培 on 16/7/27.
//  Copyright © 2016年 周英培. All rights reserved.
//

#define KWIDTH [UIScreen mainScreen].bounds.size.width
#define KHEIGHT [UIScreen mainScreen].bounds.size.height

#import "ZZMainNewsTableViewCell.h"
#import "UIImageView+WebCache.h"
@interface ZZMainNewsTableViewCell ()

@property (nonatomic,strong) UILabel *titleLabel;

@property (nonatomic,strong) UILabel *digestLabel;

@property (nonatomic,strong) UIImageView *imgsrcIcon;

@property (nonatomic,strong) UILabel *replyCountLabel;

@end

@implementation ZZMainNewsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.contentView.backgroundColor = [UIColor orangeColor];
        
        UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, 79.5, KWIDTH, 0.5)];
        
        bottomLine.backgroundColor = [UIColor blackColor];
        
        [self.contentView addSubview:bottomLine];
        
        self.titleLabel = [[UILabel alloc]init];
        self.digestLabel = [[UILabel alloc] init];
        self.imgsrcIcon = [[UIImageView alloc] init];
        self.replyCountLabel = [[UILabel alloc] init];
        
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.digestLabel];
        [self.contentView addSubview:self.imgsrcIcon];
        [self.contentView addSubview:self.replyCountLabel];
        
    }
    
    return self;
    
}

- (void)setMainNewsModel:(ZZMainNewsModel *)mainNewsModel {

    _mainNewsModel = mainNewsModel;
    
    self.titleLabel.text = mainNewsModel.title;
    
    self.digestLabel.text = mainNewsModel.digest;
    
    self.digestLabel.font = [UIFont systemFontOfSize:13];
    
    self.digestLabel.numberOfLines = 2;
    
    NSURL *url = [NSURL URLWithString:mainNewsModel.imgsrc];
    
    [self.imgsrcIcon sd_setImageWithURL:url];
    
    self.replyCountLabel.text = [NSString stringWithFormat:@"跟帖数:%@",mainNewsModel.replyCount];
    
    self.replyCountLabel.font = [UIFont systemFontOfSize:12];

}

- (void)layoutSubviews {

    [super layoutSubviews];
    
    CGFloat imageX = 8;
    
    CGFloat imageY = 8;
    
    CGFloat imageW = 100;
    
    CGFloat imageH = 64;
    
    self.imgsrcIcon.frame = CGRectMake(imageX, imageY, imageW, imageH);
    
    self.titleLabel.frame = CGRectMake(imageW + 2 * imageX, imageY, KWIDTH - imageW - 3 * imageX, 20);
    
    self.digestLabel.frame = CGRectMake(imageW + 2 * imageX, imageX + 20, KWIDTH - imageW - 3 * imageX, 35);
    
    [self.replyCountLabel sizeToFit];
    
    self.replyCountLabel.frame = CGRectMake(KWIDTH - imageX - self.replyCountLabel.bounds.size.width, 80 - self.replyCountLabel.bounds.size.height, self.replyCountLabel.bounds.size.width, self.replyCountLabel.bounds.size.height);

}


@end
